<template>
  <div class="container">
    <div style="padding:15px 0">
         <courseList :kcList="classInfo" :type="3"></courseList>
    </div>
    <div class="line"></div>  
    <div style="padding:15px 0">
       <div class="originator weui-cell" >
          <div class="weui-cell__hd">
              <div class="thumb" style="overflow:hidden;">
                  <avatar 
                    :avatar="team.user.avatar" 
                    :userId="team.user.id"></avatar>
                  <span>发起人</span>
              </div>
          </div>
          <div class="weui-cell__bd nickname">
               <div class="nickname">{{team.user.nickname}}</div> 
               <div class="time">{{team.created_at}}</div>
          </div>
      </div>
      <div class="weui-cell" >
          <div class="weui-cell__bd">
              <div class='txImg' v-if="team.team">
                  <div class='txItem' v-for="(item,idx) in team.team_mem" :key="idx"><img :src='item.avatar' /></div>
              </div>
          </div>
          <div class="weui-cell__ft remain">还差<span>{{team.small_group_max-1-(team.team.length)}}</span>人拼课成功</div>
      </div>
    </div>
    <div class="footer">
         <van-button type="info" size="large" custom-class="toBuy"  open-type="getUserInfo" @getuserinfo="bindGetUserInfo">马上拼课</van-button>
    </div>
  </div>
</template>

<script>
import courseList from "@/components/list";
import Follow from "@/components/follow"
import avatar from "@/components/avatar"
import {pingInfo} from "@/api/ping"
import {pingJoin} from "@/api/ping"
import { xdLogin } from "@/utils/login"
import {pay} from "@/utils/pay"
export default {
  components: {
      courseList,
      avatar
  },

  data () {
    return {
        team:{},
        pingId:"",
        user_id:"",
        classInfo:"",
        share_user:0
    }
  },
  methods:{
    getpingInfo(){
        this.keStart=true
        let data={};
        data.id=this.pingId;
        data.user_id=this.userId;
        pingInfo(data).then(res=>{
          if(res.code==200){
            this.classInfo=res.data,
            console.log(this.pingInfo)
          }else if(res.code==201){

          }
        }) 
    },
    tobuy(){
      let data={};
      data.id=this.classInfo.id;
      data.payment=1;
      data.share_user=this.share_user
      data.ping_team_id=this.team.ping_team_id;
      pingJoin(data).then(res=>{
         if(res.code==200){
             pay(res.data).then(res=>{
                wx.navigateBack({
                  delta: 1
                });
            })
         }
      })
    },
    bindGetUserInfo(e){
        wx.getStorage({
          key: 'token',
          success: (result) => {
             this.tobuy()
          },
          fail: () => {
            xdLogin(e).then((res)=>{
                this.tobuy()
            })
          },
          complete: () => {}
        });
          
    }
  },
  onLoad(options){
     Object.assign(this.$data, this.$options.data())
     this.team=JSON.parse(options.item);
     this.userId=wx.getStorageSync("user_info").id;
     wx.getStorageSync("share_user")?this.share_user=wx.getStorageSync("share_user"):this.share_user=0;
     this.pingId=options.id;
     this.getpingInfo()

  },
  created () {
     
  }
}
</script>
<style lang="scss">
 .footer{
    position:fixed;
    left:0;
    right:0;
    bottom:0;
    .toBuy{
        background-color:#1A84FB;
        color: #fff;
    }
  }
</style>
<style scoped lang="scss">
    .line{
        width:375px;
        height:5px;
        background:rgba(244,245,245,1);
    }
   
</style>
